var t = require;
var e = module;
var o = exports;
var n =
        (this && this.__extends) ||
        (function () {
            var t = function (e, o) {
                return (t =
                    Object.setPrototypeOf ||
                    ({__proto__: []} instanceof Array &&
                        function (t, e) {
                            t.__proto__ = e;
                        }) ||
                    function (t, e) {
                        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                    })(e, o);
            };
            return function (e, o) {
                function n() {
                    this.constructor = e;
                }
                t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
            };
        })(),
    r =
        (this && this.__decorate) ||
        function (t, e, o, n) {
            var r,
                a = arguments.length,
                i = a < 3 ? e : null === n ? (n = Object.getOwnPropertyDescriptor(e, o)) : n;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(t, e, o, n);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (r = t[s]) && (i = (a < 3 ? r(i) : a > 3 ? r(e, o, i) : r(e, o)) || i);
            return a > 3 && i && Object.defineProperty(e, o, i), i;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var a = t("Sounds"),
    i = t("Platforms"),
    s = t("LoadImgs"),
    c = t("ConfS"),
    l = cc._decorator,
    u = l.ccclass,
    p = (l.property, 0),
    f = new Array(),
    d = new Array(),
    h = (function (t) {
        function e() {
            return (null !== t && t.apply(this, arguments)) || this;
        }
        return (
            n(e, t),
            (e.prototype.init = function (t, e, o, n, r) {
                var s = this;
                if (((this.delayGroup = "cpbIcon" + ++p), i.default.platformCtrl.cpbConfig)) {
                    if ("number" == typeof t);
                    else if (!t || !t.length) return void (this.node.active = !1);
                    this.img = this.node.getChildByName("img").getComponent(cc.Sprite);
                    var c = this.node.getChildByName("rewardtxt");
                    if (
                        (c && (this.rewardtxt = c.getComponent(cc.Label)),
                        (this.yilingqu = this.node.getChildByName("yilingqu")),
                        (this.cpb文字底 = this.node.getChildByName("cpb文字底")),
                        i.default.platformCtrl.cpbAtlas && this.cpb文字底)
                    ) {
                        var l = new cc.SpriteFrame(
                            i.default.platformCtrl.cpbAtlas,
                            new cc.Rect(
                                i.default.platformCtrl.cpbConfig.文字底[0],
                                i.default.platformCtrl.cpbConfig.文字底[1],
                                i.default.platformCtrl.cpbConfig.文字底[2],
                                i.default.platformCtrl.cpbConfig.文字底[3]
                            )
                        );
                        (l.insetLeft = l.insetTop = l.insetRight = l.insetBottom = 10),
                            (this.cpb文字底.getComponent(cc.Sprite).spriteFrame = l);
                    }
                    var u = this.node.getChildByName("nameTxt");
                    u && ((this.nameTxt = u.getComponent(cc.Sprite)), (this.nameTxtWid0 = u.width));
                    var h = this.node.getChildByName("nameTxt2");
                    h && (this.nameTxt2 = h.getComponent(cc.Label)),
                        this.node.on(cc.Node.EventType.TOUCH_END, function (t) {
                            a.Sounds.playFX("点击"), i.default.platformCtrl.openCPB(s, s.cpbGameInfo, e, o, n, !0, r);
                        }),
                        "number" == typeof t
                            ? this.set(t)
                            : ((this.loopsIndex = f.indexOf(t)),
                              -1 == this.loopsIndex && ((this.loopsIndex = f.length), f.push(t), d.push(-1)),
                              this.next());
                } else this.node.active = !1;
            }),
            (e.prototype.shake = function () {
                var t = this;
                this.node.runAction(
                    cc.sequence(
                        cc.delayTime(2 + 2 * Math.random()),
                        cc.rotateTo(0.1, 15).easing(cc.easeSineInOut()),
                        cc.rotateTo(0.1, -15).easing(cc.easeSineInOut()),
                        cc.rotateTo(0.1, 15).easing(cc.easeSineInOut()),
                        cc.rotateTo(0.1, -15).easing(cc.easeSineInOut()),
                        cc.rotateTo(0.1, 15).easing(cc.easeSineInOut()),
                        cc.rotateTo(0.1, 0).easing(cc.easeSineInOut()),
                        cc.callFunc(function () {
                            t.shake();
                        })
                    )
                );
            }),
            (e.prototype.showTxt = function () {
                this.nameTxt && (this.nameTxt.node.active = !0),
                    this.nameTxt2 && (this.nameTxt2.node.active = !0),
                    this.cpb文字底 && (this.cpb文字底.active = !0);
            }),
            (e.prototype.hideTxt = function () {
                this.nameTxt && (this.nameTxt.node.active = !1),
                    this.nameTxt2 && (this.nameTxt2.node.active = !1),
                    this.cpb文字底 && (this.cpb文字底.active = !1);
            }),
            (e.prototype.clear = function () {
                i.default.delays.clear(this.delayGroup), this.node.destroy();
            }),
            (e.prototype.set = function (t) {
                var e = this;
                if (((this.cpbGameInfo = i.default.platformCtrl.cpbConfig.cpbs[t]), this.cpbGameInfo)) {
                    if (i.default.platformCtrl.cpbAtlas) {
                        var o = new cc.SpriteFrame(
                            i.default.platformCtrl.cpbAtlas,
                            new cc.Rect(
                                this.cpbGameInfo.iconRect[0],
                                this.cpbGameInfo.iconRect[1],
                                this.cpbGameInfo.iconRect[2],
                                this.cpbGameInfo.iconRect[3]
                            )
                        );
                        (this.img.spriteFrame = o),
                            this.nameTxt &&
                                ((o = new cc.SpriteFrame(
                                    i.default.platformCtrl.cpbAtlas,
                                    new cc.Rect(
                                        this.cpbGameInfo.nameRect[0],
                                        this.cpbGameInfo.nameRect[1],
                                        this.cpbGameInfo.nameRect[2],
                                        this.cpbGameInfo.nameRect[3]
                                    )
                                )),
                                (this.nameTxt.spriteFrame = o),
                                (this.nameTxt.node.width = Math.min(this.cpbGameInfo.nameRect[2], this.nameTxtWid0)));
                    } else
                        s.LoadImgs.load(this.cpbGameInfo.icon, !1, function (t) {
                            e.img && (e.img.spriteFrame = t);
                        }),
                            this.nameTxt2 &&
                                (this.nameTxt2.string =
                                    this.cpbGameInfo.name.length > 6
                                        ? this.cpbGameInfo.name.substr(0, 4) + "..."
                                        : this.cpbGameInfo.name);
                } else console.error("cpbIndex=" + t);
            }),
            (e.prototype.next = function () {
                var t = this;
                ++d[this.loopsIndex] >= f[this.loopsIndex].length && (d[this.loopsIndex] = 0),
                    this.set(f[this.loopsIndex][d[this.loopsIndex]]),
                    i.default.delays.delay({
                        time: c.DatasManager.CPA图标轮播间隔,
                        action: function () {
                            t.next();
                        },
                        group: this.delayGroup
                    });
            }),
            (e = r([u], e))
        );
    })(cc.Component);
o.default = h;
